﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using MoskieBlog.Data.Models;

namespace MoskieBlog.Data
{
    public class MoskieBlogDbContext : DbContext
    {
        public MoskieBlogDbContext()
            : base("DefaultConnection")
        {
        }

        public DbSet<User> Users { get; set; }
        public DbSet<Post> Posts { get; set; }
        public DbSet<ChalkMark> ChalkMarks { get; set; }
        public DbSet<Role> Roles { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.Entity<User>()
                .HasMany(u => u.Roles)
                .WithMany()
                .Map(x => x
                    .ToTable("UsersInRoles")
                    .MapLeftKey("UserId")
                    .MapRightKey("RoleId"));
        }
    }
}
